<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/app.css" />
	</head>

	<body>
		<nav class="mui-bar mui-bar-tab">
			<a class="mui-tab-item mui-active" href="pagesTest/index/index.html">
				<img class="mui-icon" src="images/tabBar/home-h.png" alt="" style="width: 25px;height: 25px;" />
				<span class="mui-tab-label">首页</span>
			</a>
			<a class="mui-tab-item" href="pagesTest/classify/index.html">
				<img class="mui-icon" src="images/tabBar/classify.png" alt="" style="width: 25px;height: 25px;" />
				<span class="mui-tab-label">分类</span>
			</a>
			<a class="mui-tab-item" href="pagesTest/my/index.html">
				<img class="mui-icon" src="images/tabBar/user.png" alt="" style="width: 25px;height: 25px;" />
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>

		<script src="js/mui.js"></script>
		<script type="text/javascript">
			mui.init()
			mui.plusReady(function() {
				let pages = [
					'pagesTest/index/index.html',
					'pagesTest/classify/index.html',
					'pagesTest/my/index.html'
				]
				let pageStyle = {
					bottom: '50px',
					top: 0
				}
				let self = plus.webview.currentWebview()
				let imgs = document.querySelectorAll('.mui-tab-item>img')
				let activeTab = 0

				pages.forEach(e => {
					let sub = plus.webview.create(e, e, pageStyle)
					sub.hide()
					self.append(sub)
				})
				plus.webview.show(pages[0])

				mui('.mui-bar-tab').on('tap', '.mui-tab-item', function() {
					let imgSrc = this.childNodes[1].src

					if (imgSrc.includes('home') && activeTab) {
						tabTag()
						this.childNodes[1].src = imgSrc.replace('home', 'home-h')
						activeTab = 0
					} else if (imgSrc.includes('classify') && activeTab != 1) {
						tabTag()
						this.childNodes[1].src = imgSrc.replace('classify', 'classify-h')
						activeTab = 1
					} else if (imgSrc.includes('user') && activeTab != 2) {
						tabTag()
						this.childNodes[1].src = imgSrc.replace('user', 'user-h')
						activeTab = 2
					}

					let href = this.getAttribute('href')
					plus.webview.show(href)
				})
			})
			

			function tabTag() {
				let dir = 'images/tabBar/'
				switch (activeTab) {
					case 0:
						imgs[0].src = dir + 'home.png'
						break
					case 1:
						imgs[1].src = dir + 'classify.png'
						break
					case 2:
						imgs[2].src = dir + 'user.png'
						break
				}
			}
		</script>
	</body>

</html>